home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / ssmn012c.lha / Sysmon / src / ValidateWait.c < prev   
C/C++ Source or Header  |  1995-11-20  |  3KB  |  114 lines

  1. /*
  2. **    $RCSfile: ValidateWait.c,v $
  3. **    $Filename: ValidateWait.c $
  4. **    $Revision: 0.1 $
  5. **    $Date: 1995/01/22 17:33:51 $
  6. **
  7. **    Wait for a volume to be validated by the file system (version 0.2)
  8. **    
  9. **    (C) Copyright 1995 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/alerts.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <dos/dostags.h>
  16. #include <workbench/startup.h>
  17. #define __USE_SYSBASE
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <string.h>
  21.  
  22. struct ExecBase *SysBase;
  23. struct DosLibrary *DOSBase;
  24. static struct WBStartup *wbmsg;
  25. static struct RDArgs *myrda;
  26.  
  27. static UBYTE version[] = "$VER: ValidateWait 0.2 (5.8.95)";
  28. static UBYTE template[] = "DRIVE/A,TIMEOUT/K/N";
  29.  
  30. #define    OPT_DRIVE    0
  31. #define    OPT_TIMEOUT    1
  32. #define OPTMAX        2
  33.  
  34. ULONG __saveds main(void);
  35. static void cleanexit(ULONG rc);
  36.  
  37. ULONG __saveds main(void)    /* No startup code */
  38. {
  39.   struct Process *myproc;
  40.   LONG opts[OPTMAX];
  41.   ULONG rc = 0;
  42.  
  43.   SysBase = *(struct ExecBase **)4;
  44.   DOSBase = NULL;
  45.   wbmsg = NULL;
  46.   myrda = NULL;
  47.  
  48.   myproc = (struct Process *)FindTask(NULL);
  49.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36)) == NULL)
  50.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  51.     return 100;
  52.   }
  53.  
  54.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  55.   { WaitPort(&(myproc->pr_MsgPort));
  56.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  57.     cleanexit(20);
  58.   }
  59.   else
  60.   { BPTR lock;
  61.     struct InfoData *info;
  62.     int timeout, count = 0;
  63.  
  64.     memset((char *)opts, 0, sizeof(opts));
  65.     if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  66.     { PrintFault(IoErr(),"ValidateWait");
  67.       cleanexit(20);
  68.     }
  69.     if (opts[OPT_TIMEOUT]) timeout = *((LONG *)opts[OPT_TIMEOUT]);
  70.     else timeout = 300;
  71.  
  72.     if ((lock = Lock((STRPTR)opts[OPT_DRIVE], SHARED_LOCK)) == NULL)
  73.     { PrintFault(IoErr(),"ValidateWait");
  74.       cleanexit(10);
  75.     }
  76.     if ((info = AllocVec(sizeof(struct InfoData), MEMF_PUBLIC)) == NULL)
  77.     { Printf("ValidateWait : No memory for InfoData.\n");
  78.       UnLock(lock);
  79.       cleanexit(20);
  80.     }
  81.  
  82.     do
  83.     { if (Info(lock, info) == DOSFALSE)
  84.       { PrintFault(IoErr(),"ValidateWait");
  85.     UnLock(lock);
  86.     FreeVec(info);
  87.     cleanexit(10);
  88.       }
  89.       if (info->id_DiskState != ID_VALIDATING) break;
  90.       else Delay(TICKS_PER_SECOND);
  91.       if (CheckSignal(SIGBREAKF_CTRL_C)) count = timeout;
  92.     } while (++count < timeout);
  93.  
  94.     if (count >= timeout)
  95.     { Printf("ValidateWait : Volume Validation timed out.\n");
  96.       rc = 10;
  97.     }
  98.     UnLock(lock);
  99.     FreeVec(info);
  100.   }
  101.   cleanexit(rc);
  102. }
  103.  
  104. static void cleanexit(ULONG rc)
  105. {
  106.   if (myrda) FreeArgs(myrda);
  107.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  108.   if (wbmsg)
  109.   { Forbid();
  110.     ReplyMsg((struct Message *)wbmsg);
  111.   }
  112.   Exit(rc);
  113. }
  114.